Kurs Komputerowy S
System Symboliczny
Mathematica

Listy i macierze

Tworzenie

lista={...,...,...,...}
lista[[i]]
Table[wyrażenie,{n}]
Table[(Subscript[wyrażenie, i]),{i,n}]
Table[(Subscript[wyrażenie, i]),{i, pocz, kon}]
Range[n]
Range[pocz, kon]
Range[pocz, kon, krok]

Jednowymiarowe ...

a={1,3,2,5,4,6,8,7,0,9}
a[[2]]
a[[4]]

a[[11]]

Table[x,{5}]

Table[x,{x,5}]

Table[x,{x,3,5}]

Table[x,{x,3,17,.5}]

Table[(y+4)^(2*z),{x,3,17,3}]

Range[6]

Range[3,8]

Range[3,8,0.5]

Wielowymiarowe ...

b={{1,2},{3,4},{5,6},{7,8},{9,10}}
b[[2]]
b[[2,1]]

x=.

Table[x,{5},{6}]

Table[j*x^i,{i,5},{j,4}]

Table[{i,j,j*x^i},{i,5},{j,4}]

a={{1,2},3,{3,{4,5},6},{5,6,7}}

a[[3]]

a[[3,2]]

a[[3,2,1]]

Operacje na

lista[[i]]
Part[lista,i]
Take[lista,n]    Take[lista, {n}]    Take[lista,-n]    Take[lista, {-n}]    Take[lista, {m, n}]
First[lista]
Last[lista]
Pick[lista,selektor]

a=Range[20]

a[[15]]

Part[a,15]

Part[a,15,20]

Part[a,{15,20}]

Part[a,15;;20]

Part[a,15;;20;;2]

Take[a,5]

Take[a,-5]

Take[a,{5}]

Take[a,{-5}]

Take[a,{5,9}]

First[a]
Last[a]

Pick[{1,5,4,3},{True,False,False,True}]

a

Pick[a,{1,0,0,0,1,0,1,1,0,0,0,0,1,1,1,0,0,0,0,0},1]
Pick[a,{1,0,0,0,1,0,1,1,0,0,0,0,1,1,1,0,0,0,0,0},0]

wyrazenia

d=2+x

FullForm[d]

FullForm[a]

d[[1]]
d[[2]]

d[[0]]

d[[0]]=Times

d

d[[2]]=y

d

e=Expand[(3+y)^4]

e[[3]]

e[[3,2]]

e[[3,2,2]]

e[[3,2,2]]=10

e

FullForm[e]

FullForm[a]

Drop[lista,n]    Drop[lista, {n}]    Drop[lista,-n]    Drop[lista, {-n}]    Drop[lista, {m, n}]
Rest[lista]
Most[lista]
Delete[lista, pozycja]
Position[lista, element]
Insert[lista, element, pozycja]
Prepend[lista, element]        PrependTo[lista, element]
Append[lista, element]         AppendTo[lista, element]

a

Take[a,5]

Drop[a,5]

Drop[a,-5]
Drop[a,{5}]
Drop[a,{-5}]
Drop[a,{5,9}]

Rest[a]

Most[a]

Delete[a,5]

Delete[a,{5,8}]

Delete[a,{{5},{8}}]

Clear[b,c,d,e]

a={b,c,d,b,c,e,c,d,b}

Position[a,b]

a

Insert[a,6,2]

Insert[a,6,{{2},{5}}]

Prepend[a,x]

a

PrependTo[a,x]

a

Append[a,y]

a

AppendTo[a,y]

a

Riffle[lista,element]
Reverse[lista]
Join[(Subscript[lista, 1]), (Subscript[lista, 2]),...]
Sort[lista]

a=Range[10]

e=.

Riffle[a,e]

Riffle[a,{e,f}]

Riffle[a,e,3]

Riffle[a,e,{3,7,2}]

a

Reverse[a]

b={Table[RandomInteger[20],{10}]}

a

Join[a,b]

Sort[b]

Wymiary

Length[lista]
Dimensions[lista]
TensorRank[lista]

a

Length[a]

b={{1,4},{3,2},{5,2},{5,6}}

Length[b]

Dimensions[a]

Dimensions[b]

TensorRank[a]

TensorRank[b]

b

c=Delete[b,{3,1}]

Length[c]

Dimensions[c]

TensorRank[c]

Wyświetlanie

Column[lista]
TableForm[lista]
MatrixForm[macierz]

a=Table[(2*(i+4))^j,{i,1,3},{j,1,3}]

a[[1]]

Column[a[[2]]]

TableForm[a]

%

Grid[a]

%

MatrixForm[a]

b=Delete[a,{2,1}]

Grid[b]

TableForm[b]

MatrixForm[b]

Manipulacje

ReplacePart[lista, pozycja->element]
Intersection[(Subscript[lista, 1]),(Subscript[lista, 2]),...]
Union[(Subscript[lista, 1]),(Subscript[lista, 2])]
Complement[(Subscript[lista, 1]),(Subscript[lista, 2]),...]
RotateLeft[lista,n]
RotateRight[lista,n]
Partition[lista,n]
Flatten[lista]
Permutations[lista]
Signature[lista]

a=Table[(2*(i+4))^j,{i,1,3},{j,1,3}]

ReplacePart[a,2->{x,y}]

ReplacePart[a,{2,3}->x]

ReplacePart[a,{2->x,3->x}]

a=Range[5]
b=Range[3,7]

Intersection[a,b]

Union[a,b]

Complement[a,b]

a

RotateLeft[a,2]

RotateLeft[a,5]

RotateRight[a,2]

RotateLeft[a,-2]

a=Table[(2*(i+4))^j,{i,1,3},{j,1,3}]

Grid[a]

RotateLeft[a,1]

Grid[%]

RotateLeft[a,{0,1}]

Grid[%]

b=Range[20]

Partition[b,5]

Partition[b,6]

Flatten[%]

a=Range[4]

b=Permutations[a]

Length[b]

Signature[b[[4]]]

Signature[b[[3]]]

wyrażenia:
Apply[polecenie,wyrażenie]

a=Table[x^i,{i,1,4}]

FullForm[a]

b=a

b[[0]]=Plus

b

a

Apply[Plus,a]

Plus@@a

Apply[List,a,2]

FullForm[a]

Obliczenia

(Subscript[lista, 1])+(Subscript[lista, 2])
(Subscript[lista, 1])*(Subscript[lista, 2])
(Subscript[lista, 1]).(Subscript[lista, 2])        Dot[(Subscript[lista, 1]),(Subscript[lista, 2])]
Det[macierz]
Minors[m,k]
MatrixPower[macierz,n]

a=Range[4]
b={k,l,m,n}
c=Range[10,6,-1]

a+b

a+c

a*b

a.b

Dot[a,b]

Sum[a[[i]]*b[[i]],{i,1,Length[a]}]

2.5

a=Table[(i+3)^j,{i,2},{j,2}]

Grid[a]

Det[a]

b=Table[(i+2)^j,{i,4},{j,4}]

Det[b]

Grid[b]

Minors[b,2]

a

a*a

(a^2)

a.a

MatrixPower[a,2]

Inverse[macierz]
IdentityMatrix[n]
DiagonalMatrix[wektor]
Transpose[macierz]
Eigenvalues[macierz]
Eigenvectors[macierz]
Eigensystem[macierz]
LinearSolve[m,b]

a=Table[(i+2)^j,{i,2},{j,2}]

b=Inverse[a]

a.b

Grid[%]

b.a

IdentityMatrix[3]

Grid[%]

DiagonalMatrix[{3,2,4}]

Grid[%]

Grid[a]

b=Transpose[a]
Grid[b]

a

ev=Eigenvalues[a]

v=Eigenvectors[a]

a.Transpose[v]==Transpose[v].DiagonalMatrix[ev]

a.v[[1]]//N

ev[[1]]*v[[1]]//N

Eigensystem[a]

a

b={4,5}
s=LinearSolve[a,b]

a

a.s